package com.sailfish.springbootdemo.controller.db1;

import com.sailfish.springbootdemo.configs.UserHeaderHolder;
import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.service.db1.CommonTriggerStatusService;
import com.sailfish.springbootdemo.service.db1.CoreAlgorithmService;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@CrossOrigin
@RequestMapping("/coreAlgorithm")
public class CoreAlgorithmController {

    @Autowired
    private CoreAlgorithmService coreAlgorithmService;

    @Autowired
    private CommonTriggerStatusService commonTriggerStatusService;

    @PostMapping("/calcLineBaseCapacity")
    public Result calcLineBaseCapacity(Integer pcbaLineId) {
        return coreAlgorithmService.calcLineBaseCapacity(pcbaLineId);
    }

    /**
     * 改变基线参数池触发
     *
     * @param pcbaDeviceTypeId
     * @return
     */
    @PostMapping("/changeBaseDeviceResourceStatus")
    public Result changeBaseDeviceResourceStatus(Integer pcbaDeviceTypeId) {
        coreAlgorithmService.changeBaseDeviceResourceStatus(pcbaDeviceTypeId);
        return ResultUtil.success(null);
    }

    /**
     * 改变工艺参数池触发
     *
     * @param pcbaDeviceTypeId
     * @return
     */
    @PostMapping("/changeTechDeviceResourceStatus")
    public Result changeTechDeviceResourceStatus(Integer pcbaDeviceTypeId) {
        coreAlgorithmService.changeTechDeviceResourceStatus(pcbaDeviceTypeId);
        return ResultUtil.success(null);
    }

    /**
     * 改变基线参数值引发
     */
    @PostMapping("/changeDeviceResourceBaseParamValue")
    public Result changeDeviceResourceBaseParamValue(Integer pcbaDeviceResourceId) {
        Date d = new Date();
        String userId = UserHeaderHolder.getUserId();
        coreAlgorithmService.changeDeviceResourceBaseParamValue(pcbaDeviceResourceId, d, userId);

        return ResultUtil.success(null);
    }

    /**
     * 改变工艺实际参数值引发
     */
    @PostMapping("/changeDeviceTechParamActualValue")
    public Result changeDeviceTechParamActualValue() {
        return ResultUtil.success(null);
    }

    /**
     * 改变线体设备
     */
    @PostMapping("/changeLineDevice")
    public Result changeLineDevice(Integer pcbaLineId) {
        Date d = new Date();
        String userId = UserHeaderHolder.getUserId();
        coreAlgorithmService.changeLineDevice(pcbaLineId, d, userId);
        return ResultUtil.success(null);
    }

    /**
     * 改变线体整线基线能力值
     */
    @PostMapping("/changeLineBaseCapacityValue")
    public Result changeLineBaseCapacityValue(Integer pcbaLineId) {
        Date d = new Date();
        String userId = UserHeaderHolder.getUserId();
        coreAlgorithmService.changeLineBaseCapacityValue(pcbaLineId, d, userId);
        return ResultUtil.success(null);
    }

    /**
     * 改变线体整线工艺宣称能力值
     */
    @PostMapping("/changeLineTechCapacityDeclareValue")
    public Result changeLineTechCapacityDeclareValue(Integer pcbaLineId) {
        Date d = new Date();
        String userId = UserHeaderHolder.getUserId();
        coreAlgorithmService.changeLineTechCapacityDeclareValue(pcbaLineId, d, userId);
        return ResultUtil.success(null);
    }

    /**
     * 即时刷新pcba能力匹配
     * 1.基线参数 is_related_pcba 值发生变化   type = 1
     * 2.工艺参数 is_related_pcba 值发生变化   type = 2
     * 3.整线能力 is_related_pcba 值发生变化   type = 3
     * 4.设备备注发生变化                      type = 4
     */
    @PostMapping("/changePcbaCapacity")
    public Result changePcbaCapacity(Integer type, String beforeStr, String afterStr, Integer pcbaDeviceTypeId, Integer pcbaDeviceId, Integer pcbaLineId) {
        coreAlgorithmService.changePcbaCapacity(type, beforeStr, afterStr, pcbaDeviceTypeId, pcbaDeviceId, pcbaLineId);
        return ResultUtil.success(null);
    }
}
